package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.ApplyVipListBean;
import com.wannengbang.cloudleader.utils.DateTimeUtil;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class ApplyVipListAdapter extends RecyclerView.Adapter<ApplyVipListAdapter.ViewHolder> {

    private List<ApplyVipListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public ApplyVipListAdapter(List<ApplyVipListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_apply_vip_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ApplyVipListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvStartNo.setText("开始编号：" + dataBean.getStart_no());
        holder.tvEndNo.setText("结束编号：" + dataBean.getEnd_no());
        holder.tvApplyTime.setText("申请时间：" + DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getCreate_time()) * 1000)));

        holder.tvApplyList.setText("申请记录：" + getTypeValue(dataBean.getOld_type()) + " -> " + getTypeValue(dataBean.getNew_type()));


        if (dataBean.getStatus() == 1) {
            holder.tvApplyStatus.setText("申请状态：已申请");
        } else if (dataBean.getStatus() == 2) {
            holder.tvApplyStatus.setText("申请状态：已通过");
        } else if (dataBean.getStatus() == 3) {
            holder.tvApplyStatus.setText("申请状态：已拒绝");
        }
    }

    private String getTypeValue(int type) {
        //type=1 云小宝 普通版
        //type=2 云商宝
        //type=3 云小宝 vip版
        //type=4 云小宝 plus版
        String typeValue = "";
        if (type == 1) {
            typeValue = "云小宝";
        }
        if (type == 2) {
            typeValue = "云商宝";
        }
        if (type == 3) {
            typeValue = "云小宝Vip版";
        }
        if (type == 4) {
            typeValue = "云小宝Plus版";
        }

        return typeValue;
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_start_no)
        TextView tvStartNo;
        @BindView(R.id.tv_end_no)
        TextView tvEndNo;
        @BindView(R.id.tv_apply_status)
        TextView tvApplyStatus;
        @BindView(R.id.tv_apply_time)
        TextView tvApplyTime;
        @BindView(R.id.tv_apply_list)
        TextView tvApplyList;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
